import React, { useState } from 'react'

export default function Page1() {
  const [count,setcount]=useState(0)
  const [people,setpeople]=useState({name:'安娜',age:26})
  const changeCount=()=>{
    setcount((prevCount)=>prevCount=prevCount+1)
    setcount((prevCount)=>prevCount=prevCount+1)
    setcount((prevCount)=>prevCount=prevCount+1)
    setcount((prevCount)=>prevCount=prevCount+1)
    // setcount((e)=>e+1)
    // setcount((e)=>e+1)
    // setcount((e)=>e+1)
  }
  // 会加但是不会渲染
  const changepeople=()=>{
    people.age=people.age+1
    setpeople(people)
  }
  const changepeople1=()=>{
    people.age=people.age+1
    setpeople({...people})
  }
  return (
    <div>
      <h1>useState的练习</h1>
      <div>{count}</div>
      <div>{people.name}----{people.age}</div>
      <button onClick={()=>{setcount(count+1)}}>+1</button>
      {/* 写函数 不加（） */}
      <button onClick={changeCount}>累计调用+4</button>
      <button onClick={changepeople}>对象年龄+1(不拷贝修改)</button>
      <button onClick={changepeople1}>对象年龄+1(拷贝修改)</button>
    </div>
  )
}
